package com.gitee.wsl.text.ahocorasick


import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

class UnboxedIntListTest {

//    @ParameterizedTest
//    @ValueSource(ints = [-100, -1, 0])
//    fun `throws error when initial capacity is less than one`(value: Int) {
//        assertThrows<IllegalArgumentException> { UnboxedIntList(initialCapacity = value) }
//    }
//
//    @ParameterizedTest
//    @ValueSource(doubles = [-1.0, 0.0, 1.0])
//    fun `throws error when expansion rate is less than one`(value: Double) {
//        assertThrows<IllegalArgumentException> { UnboxedIntList(expansionRate = value) }
//    }

    @Test
    fun `custom default value is respected`() {

        val list = UnboxedIntList(defaultValue = 42)
        assertEquals(list.safeGet(1_000),42)
    }

    @Test
    fun `initial capacity determines size of underlying array`() {

        val list = UnboxedIntList(initialCapacity = 1)
        assertFailsWith(IndexOutOfBoundsException::class) { list[1] }
    }

    @Test
    fun `list size always grows to accommodate the wanted index`() {

        val list = UnboxedIntList(1, 1.00001).apply {
            add(0)
            add(1)
        }

        assertEquals(list[1],1)

        list.safeSet(50, 50)
        assertEquals(list[50],50)
    }

    @Test
    fun `size accurately reflects the size of the list`(): Unit = with(UnboxedIntList()) {

        add(1)
        add(-2)
        add(3)
        assertEquals(size,3)

        safeSet(99, 7)
        assertEquals(size,100)

        pop()
        assertEquals(size,99)

        clear()
        assertEquals(size,0)
    }

    @Test
    fun `pop removes the last element`(): Unit = with(UnboxedIntList()) {

        for (i in 0..10) add(i)

        assertEquals(pop(),10)
        assertEquals(size,10) // Zero indexed
        assertEquals(pop(),9)
    }

    @Test
    fun `popping empty list throws exception`() {
        assertFailsWith<NoSuchElementException> { UnboxedIntList().pop() }
    }
}
